<template>
	<view class="wanl-withdraw">
		<view class="edgeInsetTop"> </view>
		
		<view class="padding-bj bg-white money">
			<view class="text-lg">
				<text>转入福金</text>
				<text class="text-sm wanl-gray"></text>
			</view>
			<view class="margin-tb-bj price">
				<view class="symbol">
					<text>￥</text>
				</view>
				<input type="digit" maxlength="5" focus @input="replaceInput"/>
				<view class="text-lg wanl-gray-light" @tap="emptyInput" v-if="money">
					<text class="wlIcon-shibai"></text>
				</view>
			</view>
			<view class="solid-top padding-top-bj">
				<!-- <block v-if="servicefee > 0">
					<text class="wanl-gray-light">服务费</text>
					<text class="text-price text-orange margin-left-xs">{{servicemoney}}</text>
					<text class="wanl-gray-light">，</text>
				</block> -->
				<text class="wanl-gray-light">可转入</text>
				<text class="wanl-gray-light margin-lr-xs text-price">{{usermoney}}</text>
				<!-- <text class="wanl-gray-light margin-lr-xs"></text> -->
				<!-- <text class="text-orange" v-if="usermoney > 0" @tap="moneyAll">全部</text> -->
			</view>
		</view>
		<view class="padding-bj margin-top">
			<!-- 1.0.5升级 -->
			<button class="mix-btn wanl-bg-redorange" :loading="loading" :disabled="loading" @tap="withdraw">转入</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bankData: null,
				usermoney: 0,
				money: null,
				servicemoney: 0,
				servicefee: 0,
				loading: false,
				btxdj:0
			};
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			async loadData() {
				this.$api.post({
					url: '/wanlshop/pay/initialyongjinzhuanru',
					success: res => {
						//更新全局金额
						this.setMoney(res.money);
						// this.setBtxdj(res.btxdj);
						
					}
				});
			},
			withdraw(){
				// 1.0.5升级 修复针对多次点击
				if(this.loading) return;
				this.loading = true;
				// 1.0.6升级
				let money = parseFloat(this.money),
					usermoney = parseFloat(this.usermoney);
					// let btxdj = parseFloat(this.btxdj);
				// let ktx=usermoney-btxdj;
				if(money <= 0){
					this.$wanlshop.msg('请填写正确金额');
					return;
				}
				if(money > usermoney){
					this.$wanlshop.msg('转出金额不能超过 ' + usermoney + ' 元');
					return;
				}
				this.$api.post({
					url: '/wanlshop/user/yongjinchangefujin',
					data: {
						money: money,
						// account_id: this.bankData.id
					},
					success: res => {
						this.setMoney(res.money);
						// this.setBtxdj(res.btxdj);
						// 1.0.5升级
						this.loading = false;
						// 跳转成功
						this.$wanlshop.to('/pages/page/success?type=yongjinzhuanfujin');
					}
				});
			},
			setMoney(money){
				this.usermoney = money;
				this.$store.commit('user/setUserInfo', {yongjin: money});
			},
			
			replaceInput(e){
				this.money = e.target.value;
				this.servicemoney = e.target.value > 0 ? (e.target.value*this.servicefee/1000).toFixed(2) : 0;
			},
			emptyInput(){
				this.money = null;
			},
			moneyAll(){
				this.money = this.usermoney;
			},
			getCode(str){
				str = str.replace(/\s+/g,"");
				return str.substring(str.length-4);
			},
			getType(key){
				return ['储蓄卡', '信用卡'][key];
			}
		}
	}
</script>

<style>
	
	.wanl-withdraw .money .symbol{
		font-size: 60rpx;
		margin-right: 10rpx;
	}
	
	.wanl-withdraw .money .price{
		display: flex;
		align-items: center;
	}
	.wanl-withdraw .money .price input{
		/* #ifdef MP */
		height: 100rpx;
		min-height: 100rpx;
		/* #endif */
		width: 100%;
		font-size: 100rpx;
	}
	
	.wanl-withdraw .bank{
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #ffffff;
		padding: 20rpx 25rpx;
	}
	.wanl-withdraw .bank image{
		width: 100rpx;
		height: 100rpx;
		margin-right: 25rpx;
	}
	.wanl-withdraw .bank .content{
		flex: 1;
	}
	.wanl-withdraw .bank .action{
		
	}
</style>
